package xiangya.bysj.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyUtil {
	
	private PropertyUtil(){
	}
	/**
	 * 系统初始化的properties对象
	 */
	private static Properties properties;
	
	public static Properties getProperties() {
		return properties;
	}

	public static void setProperties(Properties properties) {
		PropertyUtil.properties = properties;
	}
	
	
	/**
	 * 加载properties文件
	 * @param file 文件名字
	 * @return 返回properties对象
	 */
	public static Properties loadFile(String file){
		Properties pro = new Properties();
		InputStream ins = PropertyUtil.class.getClassLoader().getResourceAsStream(file);
		try{
			pro.load(ins);
		}catch(IOException e){
			pro = null;
			e.printStackTrace();
		}
		return pro;
	}
	
	/**
	 * 根据key获取对应的值
	 * @param file properties文件名
	 * @param key 
	 * @return 返回value
	 */
	public static String getValue(String file, String key) {
		String value = null;
		Properties pro = PropertyUtil.loadFile(file);
		if(pro != null){
			value = pro.getProperty(key);
		}
		return value;
	}
}
